trigger InvoiceNumber on Opportunity (after insert) {
	List<Opportunity> oppsTargeted=[select id, name, CreatedDate, RecordTypeId, Invoice_Number__c from Opportunity where id IN :Trigger.newMap.keyset()];
	List<Opportunity> oppsUpdate=new List<Opportunity>();
	List<RecordType> rtypes = [Select Name, Id From RecordType where sObjectType='Opportunity' and isActive=true];
	Map<String,String> opportunityRecordTypes = new Map<String,String>{};
	for(RecordType rt: rtypes)
	opportunityRecordTypes.put(rt.Name,rt.Id);
	
	Integer count=[select count() from Opportunity where RecordTypeId=:opportunityRecordTypes.get('Donations & Purchases')];
	String invoiceNumber='';
	String monthName='';
	String yearName='';
	List <String> months = new List <String>{'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'};
	for(Opportunity o : oppsTargeted)
	{	if(o.RecordTypeId == opportunityRecordTypes.get('Donations & Purchases'))
		{	monthName = months.get(o.CreatedDate.Month() - 1);
			o.Invoice_Number__c = String.valueOf(count) + '-' + monthName + '-' + String.valueOf(o.CreatedDate.Year()).substring(2);
			oppsUpdate.add(o);
		}
	}
	if(!oppsUpdate.isEmpty())
	{	update oppsUpdate;
	}
}